package com.plm.mqshequ.controller;

import com.plm.mqshequ.entity.PageModel;
import com.plm.mqshequ.nosql.MongoPostOps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;


/**
 * @author Limi
 * @create 2019-01-17 21:35
 */
@RestController
public class IndexController {

    @Autowired
    private MongoPostOps postOps;

    @GetMapping("/")
    public ModelAndView index(Model model){
        ModelAndView mv = new ModelAndView("jie/index");
        PageModel pageModel = new PageModel(1, 20);
        pageModel = postOps.findByPage(pageModel);
        model.addAttribute("posts", pageModel.getList())
            .addAttribute("total", pageModel.getTotal())
            .addAttribute("column", "main")
            .addAttribute("filter", "0");
        return mv;
    }

}
